/**
 * 结论: synchronized修饰代码块是使用monitorenter和monitorexit来实现的锁的获取和释放,默认情况下monitorexit会有两个
 */
public class Demo3 {

    private Object obj = new Object();

    public void test() {
        synchronized (obj) {
            System.out.println("hello world3");
        }
    }
}

//F:\SpringBoot-Learning\Chanpter-sync\target\test-classes>javap -v Demo3.class
//Classfile /F:/SpringBoot-Learning/Chanpter-sync/target/test-classes/Demo3.class
//  Last modified 2020-4-21; size 640 bytes
//  MD5 checksum aba3f42898a8c5e4f07dcc9719ac8879
//  Compiled from "Demo3.java"
//public class Demo3
//  minor version: 0
//  major version: 52
//  flags: ACC_PUBLIC, ACC_SUPER
//Constant pool:
//   #1 = Methodref          #2.#24         // java/lang/Object."<init>":()V
//   #2 = Class              #25            // java/lang/Object
//   #3 = Fieldref           #7.#26         // Demo3.obj:Ljava/lang/Object;
//   #4 = Fieldref           #27.#28        // java/lang/System.out:Ljava/io/PrintStream;
//   #5 = String             #29            // hello world3
//   #6 = Methodref          #30.#31        // java/io/PrintStream.println:(Ljava/lang/String;)V
//   #7 = Class              #32            // Demo3
//   #8 = Utf8               obj
//   #9 = Utf8               Ljava/lang/Object;
//  #10 = Utf8               <init>
//  #11 = Utf8               ()V
//  #12 = Utf8               Code
//  #13 = Utf8               LineNumberTable
//  #14 = Utf8               LocalVariableTable
//  #15 = Utf8               this
//  #16 = Utf8               LDemo3;
//  #17 = Utf8               test
//  #18 = Utf8               StackMapTable
//  #19 = Class              #32            // Demo3
//  #20 = Class              #25            // java/lang/Object
//  #21 = Class              #33            // java/lang/Throwable
//  #22 = Utf8               SourceFile
//  #23 = Utf8               Demo3.java
//  #24 = NameAndType        #10:#11        // "<init>":()V
//  #25 = Utf8               java/lang/Object
//  #26 = NameAndType        #8:#9          // obj:Ljava/lang/Object;
//  #27 = Class              #34            // java/lang/System
//  #28 = NameAndType        #35:#36        // out:Ljava/io/PrintStream;
//  #29 = Utf8               hello world3
//  #30 = Class              #37            // java/io/PrintStream
//  #31 = NameAndType        #38:#39        // println:(Ljava/lang/String;)V
//  #32 = Utf8               Demo3
//  #33 = Utf8               java/lang/Throwable
//  #34 = Utf8               java/lang/System
//  #35 = Utf8               out
//  #36 = Utf8               Ljava/io/PrintStream;
//  #37 = Utf8               java/io/PrintStream
//  #38 = Utf8               println
//  #39 = Utf8               (Ljava/lang/String;)V
//{
//  public Demo3();
//    descriptor: ()V
//    flags: ACC_PUBLIC
//    Code:
//      stack=3, locals=1, args_size=1
//         0: aload_0
//         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
//         4: aload_0
//         5: new           #2                  // class java/lang/Object
//         8: dup
//         9: invokespecial #1                  // Method java/lang/Object."<init>":()V
//        12: putfield      #3                  // Field obj:Ljava/lang/Object;
//        15: return
//      LineNumberTable:
//        line 1: 0
//        line 3: 4
//      LocalVariableTable:
//        Start  Length  Slot  Name   Signature
//            0      16     0  this   LDemo3;
//
//  public void test();
//    descriptor: ()V
//    flags: ACC_PUBLIC
//    Code:
//      stack=2, locals=3, args_size=1
//         0: aload_0
//         1: getfield      #3                  // Field obj:Ljava/lang/Object;
//         4: dup
//         5: astore_1
//         6: monitorenter
//         7: getstatic     #4                  // Field java/lang/System.out:Ljava/io/PrintStream;
//        10: ldc           #5                  // String hello world3
//        12: invokevirtual #6                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
//        15: aload_1
//        16: monitorexit
//        17: goto          25
//        20: astore_2
//        21: aload_1
//        22: monitorexit
//        23: aload_2
//        24: athrow
//        25: return
//      Exception table:
//         from    to  target type
//             7    17    20   any
//            20    23    20   any
//      LineNumberTable:
//        line 6: 0
//        line 7: 7
//        line 8: 15
//        line 9: 25
//      LocalVariableTable:
//        Start  Length  Slot  Name   Signature
//            0      26     0  this   LDemo3;
//      StackMapTable: number_of_entries = 2
//        frame_type = 255 /* full_frame */
//          offset_delta = 20
//          locals = [ class Demo3, class java/lang/Object ]
//          stack = [ class java/lang/Throwable ]
//        frame_type = 250 /* chop */
//          offset_delta = 4
//}
//SourceFile: "Demo3.java"